package com.itxx.keyCase.Test5;

public class Foodie extends Thread {
    private Desk desk;

    public Foodie(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (desk.getObj()) {
                if (desk.getCount() == 0) {
                    break;
                } else if (desk.isFlag()) {
                    //有
                    System.out.println("消费者吃包子中");
                    desk.setFlag(false);
                    desk.getObj().notifyAll();
                   desk.setCount(desk.getCount()-1);
                } else {
                    //没有
                    try {
                        desk.getObj().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
 /* 1.判断容器中是否有数据没有消费.
	- 有 -> 消费数据 -> 唤醒生产者生产 -> 等待
	- 没有 -> 进入到等待状态(等待生产者生产)*/


